<?php
declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class CreateProjectNodeDailyReportTable extends AbstractMigration
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function up()
    {
        $table = $this->table('original_plan_node_daily_report', ['id' => false, 'primary_key' => ['id'], 'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '原计划排期节点-日报表']);
        $table->addColumn('id', 'integer', ['identity' => true, 'signed' => false, 'limit' => 11, 'comment' => '主键ID'])
            ->addColumn('project_id', 'integer', ['limit' => 11, 'null' => false, 'signed' => false, 'default' => 0, 'comment' => '项目id'])
            ->addColumn('step_category_id', 'integer', ['limit' => 11, 'null' => false, 'signed' => false, 'default' => 0, 'comment' => '环节ID'])
            ->addColumn('entity_id', 'integer', ['limit' => 11, 'null' => false, 'signed' => false, 'default' => 0, 'comment' => '实体id'])
            ->addColumn('original_plan_node_id', 'integer', ['limit' => 11, 'null' => false, 'signed' => false, 'default' => 0, 'comment' => '原计划排期节点表ID'])
            ->addColumn('report_date', 'integer', ['limit' => 11, 'null' => false, 'signed' => false, 'default' => 0, 'comment' => '上报日期'])
            ->addColumn('task_id', 'integer', ['limit' => 11, 'null' => false, 'signed' => false, 'default' => 0, 'comment' => '任务id'])
            ->addColumn('abnormal_type', 'integer', ['limit' => 255, 'null' => false, 'signed' => false, 'default' => 0, 'comment' => '异常类型：1=需求变更,2=排期变更（被动）,3=上游延期,4=上游未交付且未解决,5=工单返修,6=申请延期,7=未处理（逾期）,8=计划外延期'])
            ->addColumn('node_type', 'integer', ['limit' => 255, 'null' => false, 'signed' => false, 'default' => 0, 'comment' => '节点类型：1=交付节点,2=完成节点'])
            ->addColumn('effect_step_category_ids', 'string', ['default' => '', 'limit' => 255, 'comment' => '影响的环节'])
            ->addColumn('last_node_id', 'integer', ['limit' => 11, 'null' => false, 'signed' => false, 'default' => 0, 'comment' => '上一个节点ID'])
            ->addColumn("desc", 'json', ['null' => true, 'comment' => '详情描述'])
            ->addIndex(['task_id', 'report_date'], ['type' => 'normal', 'name' => 'task_id'])
            ->addIndex(['project_id', 'report_date', 'task_id'], ['type' => 'normal', 'name' => 'project_task_id']);

        // 创建表
        $table->create();
    }

    public function down()
    {
        $this->table('original_plan_node_daily_report')->drop()->save();
    }
}
